package com.dz.client.controller;

import com.dz.server.pojo.User;
import com.dz.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    //去登录页
    @RequestMapping("/")
    public String toLogin(){
        return "common/login";
    }
    @RequestMapping("/login")
    public String login(String username, String password, Model model, HttpSession session){
        User user = userService.selectUser(username, password);
        if (user==null){
            model.addAttribute("msg","账号或密码错误，请重新输入");
            return "common/login";
        }
        else if (user.getFlag()==0){
            session.setAttribute("username",user.getUsername());
            return "redirect:/toClientIndex";
        }
        else
            return "redirect:/toIndex";
    }
}
